<template>
  <a-drawer
      :title="title"
      :width="800"
      placement="right"
      :closable="false"
      @close="close"
      :visible="visible"
  >

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
      
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="">
          <a-input placeholder="请输入" v-decorator="['linkerid', validatorRules.linkerid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="">
          <a-input placeholder="请输入" v-decorator="['staffno', validatorRules.staffno ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="">
          <a-input placeholder="请输入" v-decorator="['linker', validatorRules.linker ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="性别">
          <a-input placeholder="请输入性别" v-decorator="['gender', validatorRules.gender ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="出生日期">
          <a-input placeholder="请输入出生日期" v-decorator="['birthday', validatorRules.birthday ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="">
          <a-input placeholder="请输入" v-decorator="['highdegree', validatorRules.highdegree ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="学校">
          <a-input placeholder="请输入学校" v-decorator="['school', validatorRules.school ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="地址">
          <a-input placeholder="请输入地址" v-decorator="['adress', validatorRules.adress ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="联系电话">
          <a-input placeholder="请输入联系电话" v-decorator="['tel', validatorRules.tel ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="微信">
          <a-input placeholder="请输入微信" v-decorator="['wechat', validatorRules.wechat ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="">
          <a-input placeholder="请输入" v-decorator="['joineddate', validatorRules.joineddate ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="">
          <a-input placeholder="请输入" v-decorator="['position', validatorRules.position ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="">
          <a-input placeholder="请输入" v-decorator="['workstatus', validatorRules.workstatus ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="">
          <a-input placeholder="请输入" v-decorator="['province', validatorRules.province ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="">
          <a-input placeholder="请输入" v-decorator="['city', validatorRules.city ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="">
          <a-input placeholder="请输入" v-decorator="['district', validatorRules.district ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="">
          <a-input placeholder="请输入" v-decorator="['marriagebearing', validatorRules.marriagebearing ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="">
          <a-input placeholder="请输入" v-decorator="['emergencycontact', validatorRules.emergencycontact ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="">
          <a-input placeholder="请输入" v-decorator="['contacttel', validatorRules.contacttel ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="">
          <a-input placeholder="请输入" v-decorator="['isuser', validatorRules.isuser ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="密码">
          <a-input placeholder="请输入密码" v-decorator="['password', validatorRules.password ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="最近修改人">
          <a-input placeholder="请输入最近修改人" v-decorator="['updatebyid', validatorRules.updatebyid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="最近修改时间">
          <a-input placeholder="请输入最近修改时间" v-decorator="['ts', validatorRules.ts ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="状态">
          <a-input placeholder="请输入状态" v-decorator="['datastatus', validatorRules.datastatus ]" />
        </a-form-item>
		
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "LinkerStaffModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        linkerid:{rules: [{ required: true, message: '请输入!' }]},
        staffno:{rules: [{ required: true, message: '请输入!' }]},
        linker:{rules: [{ required: true, message: '请输入!' }]},
        gender:{rules: [{ required: true, message: '请输入性别!' }]},
        birthday:{rules: [{ required: true, message: '请输入出生日期!' }]},
        highdegree:{rules: [{ required: true, message: '请输入!' }]},
        school:{rules: [{ required: true, message: '请输入学校!' }]},
        adress:{rules: [{ required: true, message: '请输入地址!' }]},
        tel:{rules: [{ required: true, message: '请输入联系电话!' }]},
        wechat:{rules: [{ required: true, message: '请输入微信!' }]},
        joineddate:{rules: [{ required: true, message: '请输入!' }]},
        position:{rules: [{ required: true, message: '请输入!' }]},
        workstatus:{rules: [{ required: true, message: '请输入!' }]},
        province:{rules: [{ required: true, message: '请输入!' }]},
        city:{rules: [{ required: true, message: '请输入!' }]},
        district:{rules: [{ required: true, message: '请输入!' }]},
        marriagebearing:{rules: [{ required: true, message: '请输入!' }]},
        emergencycontact:{rules: [{ required: true, message: '请输入!' }]},
        contacttel:{rules: [{ required: true, message: '请输入!' }]},
        isuser:{rules: [{ required: true, message: '请输入!' }]},
        password:{rules: [{ required: true, message: '请输入密码!' }]},
        updatebyid:{rules: [{ required: true, message: '请输入最近修改人!' }]},
        ts:{rules: [{ required: true, message: '请输入最近修改时间!' }]},
        datastatus:{rules: [{ required: true, message: '请输入状态!' }]},
        },
        url: {
          add: "/robot/linkerStaff/add",
          edit: "/robot/linkerStaff/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'linkerid','staffno','linker','gender','birthday','highdegree','school','adress','tel','wechat','joineddate','position','workstatus','province','city','district','marriagebearing','emergencycontact','contacttel','isuser','password','updatebyid','ts','datastatus'))
		  //时间格式化
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              // that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>